/*
 * Copyright (c) 2013.
 * 游戏服务器核心代码编写人陈磊拥有使用权
 * 联系方式：E-mail:13638363871@163.com ;qq:502959937
 * 个人博客主页：http://my.oschina.net/chenleijava
 */

package com.dc.gameserver.serverCore.service.battle.coreBattleLogic.differentCardType;

import com.dc.gameserver.baseConfig.Config;
import com.dc.gameserver.hardCode.CardType;
import com.dc.gameserver.serverCore.service.battle.GameFormula;
import com.dc.gameserver.serverCore.service.battle.coreBattleLogic.AbstractDifferentLogic;
import com.dc.gameserver.serverCore.service.cardModule.CardBox;
import com.dc.gameserver.serverCore.service.cardModule.CardBoxManager;
import com.dc.gameserver.serverCore.service.character.GameCharacter;
import org.springframework.stereotype.Service;

/**
 * @author 石头哥哥</br>
 *         Project : gameServer1.1</br>
 *         Date: 13-11-2  11</br>
 *         Time: 下午4:47</br>
 *         Connect: 13638363871@163.com</br>
 *         packageName: Server.ServerCore.Service.fightProcess.differentCardType</br>
 *         注解：23  防御+攻击
 */
@Service
public class d_defence_attack extends AbstractDifferentLogic {


    @Override
    public void PostConstruct() {
        IDIFFERENTS[Integer.parseInt(CardType.DEFENCE_TYPE.getType()+""+CardType.ATTACK_TYPE.getType())]=this;
    }

    /**
     * 处理不同类型牌的逻辑
     * @param p1   优先级高的玩家 防御
     * @param p2   优先级低的玩家   攻击
     */
    @Override
    public void differentLogicHandle(GameCharacter p1,GameCharacter p2) {
        CardBox cardBox= CardBoxManager.getCardBoxByID(p1.getCardBoxID());
        CardBoxManager.DeffenceCompute(p1);
        cardBox.flushBloodAndMagic();

        //p2 ---attack-->p1,hurt
        int garms= GameFormula.grams(p2.getSelfFiveType(),p1.getSelfFiveType());
        int hurt=0;
//        int p1Blood=p1.getCurrentBlood();
        int p1Shield=p1.getCurrentShield();
        int p1Defence=p1.getDefence();
        int p2Attack=p2.getAttack();
        if (garms== 0x1){
            hurt=GameFormula.attackHurtWithGrams(p1Defence, p2Attack);
        }else if (garms== 0x2){
            hurt=GameFormula.attackHurtWithUnGrams(p1Defence, p2Attack);
        } else {
            hurt=GameFormula.attackHurtWithGramsed(p1Defence, p2Attack);
        }
        if (hurt<=0){
            hurt=0;
            hurt= Config.DEFAULT_VALUE.GAME_VALUE.hurt;
        }

        //p2对p1进行物理攻击
//        if (p1Shield>hurt){
//            p1.setCurrentShield(p1Shield-hurt);
//        } else {
//            if (p1Shield==0){
//                p1.setCurrentBlood(p1Blood-hurt);
//            }else {
//                p1.setCurrentBlood(p1Blood+p1Shield-hurt);
//                p1.setCurrentShield(0);  //next time will be 0
//            }
//        }
        p1.setCurrentShield(p1Shield-hurt);
        cardBox.sendHurtRule(p1.getID(),hurt,p2.getBattleSkillID());
        if (p1.getCurrentShield()<=0){
            p1.setCurrentShield(0);
//            p1.setCurrentBlood(0);
            //被攻击掉血
            cardBox.flushBloodAndMagic();
            cardBox.notifyPkResult(p2);
            CardBoxManager.clearPkResourceWithRoundOver(cardBox.getCardBoxID());
        } else {
            cardBox.flushBloodAndMagic();
            cardBox.resetRoundResource();
        }
    }
}
